<template>
	<view @click="bindClick">
		<slot></slot>	
	</view>
</template>

<script setup>
	import store from '@/store/index.js';
	import mixins from '@/common/js/mixins.js';
	import {
		ref,
		reactive,
		computed,
		getCurrentInstance,
		onMounted
	} from 'vue'
	import {
		onReady,
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	const isLogin = computed(() => {
		return store.getters.get_isLogin
	})
	const {
		proxy,
	} = getCurrentInstance()
	const {
		nav,
		navLogin,
		navGLogin,
		uniRequestPayment,
		modal
	} = proxy.$util;
	const props = defineProps({
		houseType:{ //房屋类型【1二手房2新房3-租房】
			type: [String, Number],
			default: '',
		},
		houseId:{ //房源ID
			type: [String, Number],
			default: '',
		},
		linkUserType:{ //联系人员【1-房东2-管家3-平台】
			type: [String, Number],
			default: '',
		}
	})
	onMounted(()=>{
		// getData();
	})
	const telNumber = ref('');
	const isAuth = ref(false)
	const apiMsg = ref('稍后再试');
	const apiCode = ref(false);
	const bindClick = async () => {
		if(!isLogin.value){
			uni.$u.toast('请先登录');
			return
		}
		await getData();
		if(!telNumber.value){
			if(apiCode.value === 203){
				modal({
					content: apiMsg.value,
					showCancel: true,
					confirmText:'开通会员'
				}).then(()=>{
					navLogin('/pagesSub/buyTaocan/buyTaocan')
				})
			}else{
				uni.$u.toast(apiMsg.value);
			}
			// uni.$u.toast('暂无联系方式');
			return;
		}
		uni.makePhoneCall({
			phoneNumber:telNumber.value
		});
	}

	const getData = async () => {
		// uni.showLoading({
		// 	title: '加载中'
		// });
		if(!isLogin.value){
			return
		}
		await proxy.$u.api.houseLinkTel({
			house_type:props.houseType,
			house_id:props.houseId,
			link_user_type:props.linkUserType,
		}).then(res => {
			let {
				data,
				code,
				msg
			} = res;
			apiMsg.value = msg;
			apiCode.value = code;
			if (code == 200) {
				isAuth.value = true;
				telNumber.value = data;
			}else{
				
			}
		})
	}
</script>

<style>

</style>